﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;
using System.Data.SqlClient;

namespace Nivdal
{
    public partial class ListTransferListedPlayers : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.ListTransferListedPlayers_PageTitle;
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                Response.Redirect("Default.aspx"); 
            
            
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            OnlineUser ou = (OnlineUser)Session["User"];
            //this.Title = Resources.Resource.ListTransferListedPlayers_Title + " - " + GND.ReturnAppTitle();
            
            if (ou.TeamId == "Null")
                Response.Redirect("~/GeneralMessage.aspx?MessageString=M74ggdizz5wfeh");
            
            if (!IsPostBack)
            {
                CheckedCountHiddenField.Value = "0";
                try
                {
                    if (Session["SearchTransferMarketValues"] != null)
                    {
                        TransferMarket tm = (TransferMarket)Session["SearchTransferMarketValues"];

                        this.SqlDataSource1.SelectParameters.Add("MinInstincts", tm.InstinctsMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxInstincts", tm.InstinctsMax);
                        this.SqlDataSource1.SelectParameters.Add("MinGoalkeeping", tm.GoalkeepingMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxGoalkeeping", tm.GoalkeepingMax);
                        this.SqlDataSource1.SelectParameters.Add("MinPositioning", tm.PositioningMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxPositioning", tm.PositioningMax);
                        this.SqlDataSource1.SelectParameters.Add("MinStamina", tm.StaminaMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxStamina", tm.StaminaMax);
                        this.SqlDataSource1.SelectParameters.Add("MinPower", tm.PowerMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxPower", tm.PowerMax);    
                        this.SqlDataSource1.SelectParameters.Add("MinTackling", tm.TacklingMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxTackling", tm.TacklingMax);
                        this.SqlDataSource1.SelectParameters.Add("MinHeading", tm.HeadingMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxHeading", tm.HeadingMax);
                        this.SqlDataSource1.SelectParameters.Add("MinQuickness", tm.QuicknessMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxQuickness", tm.QuicknessMax);
                        this.SqlDataSource1.SelectParameters.Add("MinTechnique", tm.TechniqueMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxTechnique", tm.TechniqueMax);
                        this.SqlDataSource1.SelectParameters.Add("MinShortPassing", tm.ShortPassingMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxShortPassing", tm.ShortPassingMax);
                        this.SqlDataSource1.SelectParameters.Add("MinLongPassing", tm.LongPassingMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxLongPassing", tm.LongPassingMax);
                        this.SqlDataSource1.SelectParameters.Add("MinShooting", tm.ShootingMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxShooting", tm.ShootingMax);
                        this.SqlDataSource1.SelectParameters.Add("MinCharisma", tm.CharismaMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxCharisma", tm.CharismaMax);
                        this.SqlDataSource1.SelectParameters.Add("MinExperience", tm.ExperienceMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxExperience", tm.ExperienceMax);
                        this.SqlDataSource1.SelectParameters.Add("MinAge", tm.AgeMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxAge", tm.AgeMax);
                        this.SqlDataSource1.SelectParameters.Add("PlayerType", tm.PlyerTyperadio);
                        this.SqlDataSource1.SelectParameters.Add("Nationality", tm.Nationality);
                        this.SqlDataSource1.SelectParameters.Add("Deadline", tm.Deadline);
                        this.SqlDataSource1.SelectParameters.Add("MinBid", tm.CurrentBidMin);
                        this.SqlDataSource1.SelectParameters.Add("MaxBid", tm.CurrentBidMax);
                        this.SqlDataSource1.SelectParameters.Add("PosGK", tm.PosGK);
                        this.SqlDataSource1.SelectParameters.Add("PosDef", tm.PosDef);
                        this.SqlDataSource1.SelectParameters.Add("PosMid", tm.PosMid);
                        this.SqlDataSource1.SelectParameters.Add("PosFor", tm.PosFor);
                        this.SqlDataSource1.SelectParameters.Add("PosLeft", tm.PosLeft);
                        this.SqlDataSource1.SelectParameters.Add("PosCen", tm.PosCen);
                        this.SqlDataSource1.SelectParameters.Add("PosRight", tm.PosRight);
                        this.SqlDataSource1.SelectParameters.Add("StrongFoot", tm.StrongFoot);
                        this.SqlDataSource1.SelectParameters.Add("Language", ou.Language);
                        
                    }
                }
                //catch { Response.Redirect("~/TeamHomePage.aspx"); }
                catch { };
            }
        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }

        protected void CompareSelected(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            OnlineUser ou = (OnlineUser)Session["User"];
            string PlayerId;
            GND.ExecNivdalSQL("UserId", "Nivdal_InitPlayerCompareForUser", ou.UserId);
            foreach (ListViewItem item in ListView1.Items)
            {
                if ((item.FindControl("CompareCheckBox") as CheckBox).Checked)
                {
                    PlayerId = (item.FindControl("PlayerIdHiddenField") as HiddenField).Value;
                    GND.ExecNivdalSQL("UserId", "PlayerId", "Nivdal_AddPlayerCompare", ou.UserId, PlayerId);
                }
            }

            Response.Redirect("ComparePlayers.aspx");
        }

        protected bool IsPremiumUser()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            return (ou.IsPremium);
        }


    }
}